﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using ADministration.Web;
using System.ServiceModel.DomainServices.Client;

namespace ADministration.Views
{
    public partial class Events : Page
    {
        private TicketsDomainContext context;

        public Events()
        {
            InitializeComponent();

            context = new TicketsDomainContext();
        }

        //// Executes when the user navigates to this page.
        //protected override void OnNavigatedTo(NavigationEventArgs e)
        //{
        //    EntityQuery<Category> queryCategory = context.GetCategoriesQuery();

        //    context.Load(queryCategory, OnLoadCategories, null);
        //}

        //private void OnLoadCategories(LoadOperation<Category> operation)
        //{
        //    if (!operation.HasError)
        //    {
        //        //comboBoxEventCategory.ItemsSource = context.Categories;
        //    }
        //}

        private void eventDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        //private void categoryDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        //{

        //    if (e.HasError)
        //    {
        //        System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
        //        e.MarkErrorAsHandled();
        //    }
        //}

        private void buttonEditSaveChanges_Click(object sender, RoutedEventArgs e)
        {

            //this.busyIndicator.IsBusy = true;
            //SubmitOperation so = 
                context.SubmitChanges();
            //so.Completed += new EventHandler(so_Completed);
        }

        void so_Completed(object sender, EventArgs e)
        {
            context.Load(context.GetEventsQuery(), OnContextLoaded, null);
        }

        private void OnContextLoaded(LoadOperation<Event> operation)
        {
            if (operation.HasError)
            {
                throw operation.Error;
            }
            else
            {
                this.busyIndicator.IsBusy = false;
            }
        }

        private void categoryDomainDataSource_LoadedData_1(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

    }
}
